package com.life.utils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;

import com.life.model.LifeModel;
import com.life.rule.ILifeRule;

public class LoggerUtil
{
   static HashMap<Integer,boolean[][]>storage = new HashMap<Integer,boolean[][]>();
   static HashMap<Integer,Integer>lifeStorage = new HashMap<Integer,Integer>();
   static HashMap<Integer,ILifeRule>ruleStorage = new HashMap<Integer,ILifeRule>();
   
   public static void put(Integer generationValue,boolean[][] model,int lifeCount,ILifeRule currentRule)
   {
       storage.put(generationValue,model);
       lifeStorage.put(generationValue,new Integer(lifeCount));
       ruleStorage.put(generationValue,currentRule);
   }
   
   public static boolean[][] get(Integer generationValue)
   {
       return storage.get(generationValue);
   }
   
   public static void reset()
   {
       storage.clear(); 
       lifeStorage.clear();
       ruleStorage.clear();
   }
   
   public static int getSize()
   {
       return lifeStorage.size();
   }
   
   public static ArrayList<boolean[][]> getModels()
   {
       ArrayList<boolean[][]>results = new ArrayList<boolean[][]>();
       
       ArrayList<Integer>keyList = new ArrayList<Integer>(storage.keySet());
       
       Collections.sort(keyList);
       
       for(int i = 0; i < keyList.size(); i++)
       {
	   results.add(storage.get(keyList.get(i)));
       }
       
       return results;
   }
   
   public static int getLife(int generation)
   {
       return (Integer)lifeStorage.get(new Integer(generation)).intValue();
   }
   
   public static ILifeRule getRule(int generation)
   {
       return ruleStorage.get(new Integer(generation));
   }
}
